<template>
	<view>
		<view class="cu-list menu" >
		
		<view class="cu-item" v-for="item in list" v-if="item.extraData.name" >
		 <view class="content padding-tb-sm">
		 	<view class="text-gray text-sm">
		 		<text class="cuIcon-title margin-right-xs"> </text> 预约服务：<text class="text-black" >{{item.extraData.service_name}}</text>  </view>
		 	<view class="text-gray text-sm" @click="callphone(item.extraData.phone)">
		 		<text class="cuIcon-phone margin-right-xs"> </text> 联系方式：<text class="text-black" >{{item.extraData.name}} {{item.extraData.phone}}</text> </view>
				<view class="text-gray text-sm">
					<text class="cuIcon-time margin-right-xs"> </text>预约时间： <text class="text-black" >{{item.extraData.date}}</text> </view>
				<view class="text-gray text-sm" v-if="item.content">
					<text class="cuIcon-remind margin-right-xs padding-left-sm"> 备注：</text> <text class="text-black" > {{item.content}}</text> </view>
					
		 </view>
		 <view class="action">
			 <view v-if="item.status==1 && is_admin" class="cu-btn round bg-green shadow " @click="check(item.id)"><text class="cuIcon-check margin-right-xs "></text>己处理</view>
			  
		     <view v-else-if="item.status==1 " class="cu-btn round bg-green shadow " @click="close(item.id)"><text class="cuIcon-close margin-right-xs "></text>取消预约</view>	
			  
			 <view v-else-if="item.status==2" class="cu-tag light bg-grey ">己取消</view>	
			 <view v-else-if="item.status==3" class="cu-tag light bg-green ">己处理</view>	
		 </view>
		</view>
		</view>
			<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>


<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import beeApp from '../../beeApp.js';
	 
	export default {
		components: {
			uniLoadMore,
		 
		},
		data() {
			return {
				isEmpty: 0,
				loadingType: 'more',
				page_no: 1,
				list:[],
				is_admin:0,
			}
		},
		onPullDownRefresh() {
			uni.stopPullDownRefresh();
			this.getUserInfo();
		},
		onReachBottom() {
			this.loadData();
		},
		
		onLoad(options) {
			this.id = options.id;
			// uni.setNavigationBarTitle({
			// 	title:options.title
			// })
			this.getUserInfo();
			
		
		},
		methods: {
			getUserInfo: function() {
				var that = this;
				beeApp.api("/api/user/info", {
					store_id: -1,
					fields: "user_id,store_id,phone,admin"
				}, function(res) {
					if (res.code != 200) {
						beeApp.alert(res.msg);
						return;
					}
					that.user_info = res.data;
					that.is_admin = res.data.admin;
					that.loadData("reload");
			
				});
			},
			close(id){
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确定取消预约吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							that.updateStatus(id,2); 
						}
					}
				 })
			},
			check(id){
				this.updateStatus(id,3); 
			},
			updateStatus(id,stauts){
				beeApp.api(
					'sns/topic/updateStatus', {
						id: id,
						status: stauts,
					},
					res => {
						if (res.code != 200) { //有错误请求三次，如果还是失败就放弃了
						    beeApp.alert(res.msg);
							return;
						}
						
						this.loadData("reload");
						beeApp.alert("操作成功");
					})
			},
		    callphone(phone){
			 uni.makePhoneCall({
			 	phoneNumber:phone
			 })	
			},
			loadData(type) {
				if (type == 'reload') {
					this.list = [];
					this.page_no = 1;
					this.loadingType = 'more';
				}
				//没有更多直接返回
		
				if (this.loadingType == 'loading' || this.loadingType === 'nomore') {
					return;
				}
				 
				beeApp.api(
					'sns/topic/list', {
						page: this.page_no,
						showType: this.is_admin==1? 'all':"my",
						limit: 20,
						pid: 94,
						order: "id desc"
					},
					res => {
						if (res.code != 200) { //有错误请求三次，如果还是失败就放弃了
							this.loadingType = 'nomore';
							return;
						}
						var list = res.data.list;
						if (list && list.length > 0) {
							this.list = this.list.concat(list);
							this.page_no++;
							this.loadingType = 'more';
						} else {
							this.loadingType = 'nomore';
						}
						
						if(this.list.length==0){
							this.isEmpty=1;
						}else{
							this.isEmpty = 0;
						}
					}
				);
			}
		}
	}
</script>

<style>
</style>
